Linux开发

推荐列表 站点导航

当前位置:首页 > 服务器技术 > Linux开发 >

Python实现Linux环境下的ls命令

来源:网络整理  作者:网友投稿  发布时间:2020-12-29 16:30
在Linux下使用ls命令结合正则表达式,能够高效地进行文件搜索,并通过参数操作文件,于是就想用Python实现这个功能...

- ,并通过参数操作文件。

import os import re import sys path = os.getcwd() substr = raw_input(The sub-string of the file (Support for Regular Expression): ) reg = r + substr count = 0 totalSize = 0 fileList = os.listdir(path) def getFileSize(filePath): return os.path.getsize(filePath) def humanReadFileSize(fileByte): # fileByte = str(getFileSize(filePath)) if fileByte == 0: return elif fileByte 1024: # B fileSize = str(fileByte) + B elif fileByte 1024*1024: # KB fileSize = str(fileByte/1024.0) + KB elif fileByte 1024*1024*1024: # MB fileSize = str(fileByte/1024.0/1024.0) + MB else: # GB fileSize = str(fileByte/1024.0/1024.0/1024.0) + GB return fileSize for fileName in fileList: if re.match(reg, count, fileName) fileSize = getFileSize(filePath) totalSize = totalSize+fileSize print \t, 在Linux下使用ls命令结合正则表达式,于是就想用Python实现这个功能以便在Windows上使用, )。

humanReadFileSize(fileSize).ljust(30, total size: %s % (count, fileName): count = count+1 filePath = os.path.join(path, humanReadFileSize(totalSize)) , fileName print -*160 if len(sys.argv)!=1: if sys.argv[1] == remove: os.remove(filePath) print \n\t\t%d file(s) in total,能够高效地进行文件搜索,。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/server/kaifa/10741.shtml

相关文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

Python实现Linux环境下的ls命令

2020-12-29 编辑:网友投稿

- ,并通过参数操作文件。

import os import re import sys path = os.getcwd() substr = raw_input(The sub-string of the file (Support for Regular Expression): ) reg = r + substr count = 0 totalSize = 0 fileList = os.listdir(path) def getFileSize(filePath): return os.path.getsize(filePath) def humanReadFileSize(fileByte): # fileByte = str(getFileSize(filePath)) if fileByte == 0: return elif fileByte 1024: # B fileSize = str(fileByte) + B elif fileByte 1024*1024: # KB fileSize = str(fileByte/1024.0) + KB elif fileByte 1024*1024*1024: # MB fileSize = str(fileByte/1024.0/1024.0) + MB else: # GB fileSize = str(fileByte/1024.0/1024.0/1024.0) + GB return fileSize for fileName in fileList: if re.match(reg, count, fileName) fileSize = getFileSize(filePath) totalSize = totalSize+fileSize print \t, 在Linux下使用ls命令结合正则表达式,于是就想用Python实现这个功能以便在Windows上使用, )。

humanReadFileSize(fileSize).ljust(30, total size: %s % (count, fileName): count = count+1 filePath = os.path.join(path, humanReadFileSize(totalSize)) , fileName print -*160 if len(sys.argv)!=1: if sys.argv[1] == remove: os.remove(filePath) print \n\t\t%d file(s) in total,能够高效地进行文件搜索,。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/server/kaifa/10741.shtml

相关文章

风云图片

推荐阅读

返回Linux开发频道首页